package com.dgut.courses_selecting_sys.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.dgut.courses_selecting_sys.dto.UserCourseListDto;
import com.dgut.courses_selecting_sys.entity.UserCourse;
import com.dgut.courses_selecting_sys.mapper.UserCourseMapper;
import com.dgut.courses_selecting_sys.service.IUserCourseService;
import com.dgut.courses_selecting_sys.vo.UserCourseListVo;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author yuec
 * @since 2020-08-16
 */
@Service
public class UserCourseServiceImpl extends ServiceImpl<UserCourseMapper, UserCourse> implements IUserCourseService {

    @Autowired
    UserCourseMapper userCourseMapper;

    @Override
    public List<UserCourseListVo> listByCourseId(int courseId) {
        List<UserCourseListDto> userCourseListDtos = userCourseMapper.listByCourseId(courseId);
        List<UserCourseListVo> list= new ArrayList<>(userCourseListDtos.size());
        userCourseListDtos.stream().forEach(
                e->{
                    UserCourseListVo userCourseListVo = new UserCourseListVo();
                    Date gmtCreate = e.getGmtCreate();
                    SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                    userCourseListVo.setGmtCreate(simpleDateFormat.format(gmtCreate));
                    userCourseListVo.setSex(e.getSex().equals(1)?"男":"女");
                    userCourseListVo.setUserName(e.getUserName());
                    list.add(userCourseListVo);
                }
        );
        return list;
    }
}
